package net.lulihu.common_util.jdbc.template;

import net.lulihu.common_util.jdbc.annotation.Column;
import net.lulihu.common_util.jdbc.model.UpdateAnnotationDescriptor;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * 修改sql模板
 */
public class UpdateSqlTemplate extends SqlTemplate<String, UpdateAnnotationDescriptor> {


    @Override
    boolean hasContinue(Field field) {
        return field.getAnnotation(Column.class) == null;
    }

    @Override
    Map<String, UpdateAnnotationDescriptor> fieldCache() {
        return new HashMap<>();
    }

    @Override
    void columnDescriptor(Map<String, UpdateAnnotationDescriptor> fieldCache, Field field) {
        UpdateAnnotationDescriptor descriptor = new UpdateAnnotationDescriptor();
        descriptor.setColumnName(field.getAnnotation(Column.class).value());
        fieldCache.put(field.getName(), descriptor);
    }


    /*---------------------------饿汉式单例*/
    private static final UpdateSqlTemplate updateSqlTemplate;

    static {
        updateSqlTemplate = new UpdateSqlTemplate();
    }

    private UpdateSqlTemplate() {
    }

    public static UpdateSqlTemplate getInstance() {
        return updateSqlTemplate;
    }

}
